package common.adapters;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public abstract class AbstractListAdapter<T> extends BaseAdapter {

	protected Context context;
	protected List<T> list;

	public AbstractListAdapter(Context ctx, List<T> list){
		this.context = ctx;
		this.list = list;
	}
	public int getCount() {
		return list.size();
	}

	public T getItem(int index) {
		return list.get(index);
	}

	public long getItemId(int id) {
		return id;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null){
			convertView = View.inflate(context, getResources(), null);
		}
		T t = list.get(position);
		init(convertView, t);
		return convertView;
	}
	
	public abstract int getResources();
	public abstract void init(View convertView, T t);
}
